package cn.mldn.amr.service.impl;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.mldn.amr.dao.ActionDAO;
import cn.mldn.amr.dao.EmpDAO;
import cn.mldn.amr.dao.GroupsDAO;
import cn.mldn.amr.service.IEmpService;
import cn.mldn.amr.service.abs.AbstractService;
import cn.mldn.amr.vo.Emp;
import cn.mldn.amr.vo.Groups;
@Service("empService")
public class IEmpServiceImpl extends AbstractService implements IEmpService{

	@Resource
	private EmpDAO empDAO;
	@Resource
	private GroupsDAO groupsDAO;
	@Resource
	private ActionDAO actionDAO; 
	
	@Override
	public boolean login(Emp vo) throws Exception {
		if(this.empDAO.findLogin(vo)){
			//取得所有对应的权限组数据
			List<Groups> allGroups = groupsDAO.findAllByDept(vo.getDept().getDid());
			Iterator<Groups> iter = allGroups.iterator();
			while (iter.hasNext()){
				Groups g = iter.next();
				//为每一个权限组设置权限数据
				g.setAllActions(actionDAO.findAllByGroups(g.getGid()));
			}
			// 获取当前用户所在部门并设置权限组
			vo.getDept().setAllGroups(allGroups);
			return true;
			
		}
		
		
		return false;
	}

}
